package com.ruoyi.edge.gateway.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.edge.gateway.domain.Synchronization;
import com.ruoyi.edge.gateway.service.SynchronizationService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 数据同步任务
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/synchronization")
public class SynchronizationController extends BaseController {

    private final SynchronizationService synchronizationService;

    /**
     * 获取列表
     */
    @SaCheckPermission("edge:synchronization:listPage")
    @GetMapping("/listPage")
    public TableDataInfo<Synchronization> listPage(Synchronization synchronization, PageQuery pageQuery) {
        return synchronizationService.listPage(synchronization, pageQuery);
    }

    @SaCheckPermission("edge:synchronization:get")
    @GetMapping("/get")
    public R<Synchronization> get(String id) {
        return synchronizationService.get(id);
    }

    /**
     * 新增
     */
    @SaCheckPermission("edge:synchronization:add")
    @PostMapping("add")
    public R<String> add(@RequestBody Synchronization synchronization) {
        return synchronizationService.add(synchronization);
    }

    /**
     * 编辑
     */
    @SaCheckPermission("edge:synchronization:edit")
    @PutMapping("edit")
    public R<String> edit(@RequestBody Synchronization synchronization) {
        return synchronizationService.edit(synchronization);
    }

    /**
     * 删除
     */
    @SaCheckPermission("edge:synchronization:remove")
    @DeleteMapping("remove")
    public R<String> remove(String id) {
        return synchronizationService.remove(id);
    }

    /**
     * 修改状态
     */
    @SaCheckPermission("edge:synchronization:editStatus")
    @PutMapping("editStatus")
    public R<String> editStatus(@RequestParam("id") String id,
                                @RequestParam("status")Integer status) {
        return synchronizationService.editStatus(id, status);
    }

}
